<?php
include_once("../globals.php");
require_once("$srcdir/formdata.inc.php");
$_SESSION["encounter"] = "";

// Fetching the password expiration date

$q = $_REQUEST['authUser'];
$provider_session_id = "";
$result = sqlStatement("select id from users where username = '" . $q . "'");
if ($row = sqlFetchArray($result)) {
    $provider_session_id = $row['id'];
    $_SESSION['pc_username']="__PC_ALL__";
}

$result2 = sqlStatement("select facility_id from users_facility where table_id = '$provider_session_id'");
if($row2 = sqlFetchArray($result2)){
    $_SESSION['pc_facility'] = $row2['facility_id'];
}



$is_expired = false;
if ($GLOBALS['password_expiration_days'] != 0) {
    $is_expired = false;
    $q = formData('authUser', 'P');
    $result = sqlStatement("select pwd_expiration_date from users where username = '" . $q . "'");
    $current_date = date("Y-m-d");
    $pwd_expires_date = $current_date;
    if ($row = sqlFetchArray($result)) {
        $pwd_expires_date = $row['pwd_expiration_date'];
    }

// Displaying the password expiration message (starting from 7 days before the password gets expired)
    $pwd_alert_date = date("Y-m-d", strtotime($pwd_expires_date . "-7 days"));

    if (strtotime($pwd_alert_date) != "" && strtotime($current_date) >= strtotime($pwd_alert_date) &&
            (!isset($_SESSION['expiration_msg']) or $_SESSION['expiration_msg'] == 0)) {

        $is_expired = true;
        $_SESSION['expiration_msg'] = 1; // only show the expired message once
    }
}

if ($is_expired) {
    $frame1url = "pwd_expires_alert.php"; //php file which display's password expiration message.
} else if (!empty($_POST['patientID'])) {
    $patientID = 0 + $_POST['patientID'];
    $frame1url = "../patient_file/summary/demographics.php?set_pid=$patientID";
} else if ($GLOBALS['athletic_team']) {
    $frame1url = "../reports/players_report.php?embed=1";
} else if (isset($_GET['mode']) && $_GET['mode'] == "loadcalendar") {
    $frame1url = "calendar/index.php?pid=" . $_GET['pid'];
    if (isset($_GET['date']))
        $frame1url .= "&date=" . $_GET['date'];
}
else if ($GLOBALS['concurrent_layout']) {
    // new layout
    if ($GLOBALS['default_top_pane']) {
        $frame1url = $GLOBALS['default_top_pane'];
    } else {
        $frame1url = "main_info.php";
    }
} else {
    // old layout
    $frame1url = "main.php?mode=" . $_GET['mode'];
}

$nav_area_width = $GLOBALS['athletic_team'] ? '230' : '130';
if (!empty($GLOBALS['gbl_nav_area_width']))
    $nav_area_width = $GLOBALS['gbl_nav_area_width'];
?>
<html>
    <head>
        <link href="../../images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <title>Expediente M&eacute;dico | Saludaunclic.com</title>
        <link rel="stylesheet" type="text/css" href="<?php echo $web_root; ?>/interface/themes/style_metal.css">
        <link rel="stylesheet" type="text/css" href="<?php echo $web_root; ?>/interface/themes/nightingale.css">
        <link rel="stylesheet" type="text/css" href="<?php echo $web_root; ?>/interface/themes/main.css">
        <link rel="stylesheet" type="text/css" href="<?php echo $web_root; ?>/interface/themes/dropmenu.css">
        <link rel="stylesheet" type="text/css" href="<?php echo $web_root; ?>/interface/themes/tabs.css" media="screen, projection"/>
        <link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300|Anton|Oswald' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" type="text/css" href="<?php echo $web_root; ?>/interface/themes/jquery-accordion.css" >

        <!-- Add jQuery library -->
        <script type="text/javascript" src="<?php echo $web_root; ?>/library/js/jquery-1.10.0.min.js"></script>
        <!--<script type="text/javascript" src="../../library/js/jquery-1.7.2.min.js"></script>-->
        <script type="text/javascript" src="../../library/js/jquery.fancybox.pack.js"></script>
        <link rel="stylesheet" type="text/css" href="<?php echo $web_root; ?>/interface/themes/jquery.fancybox.css?v=2.1.5" media="screen"/>

        <!--[if IE 7]>
                <script src="/interface/js/jquery.pseudo.js"></script>
        <![endif]--> 

        <script language='JavaScript'>

            /*$( document ).ready(function() {
             $('#panelHandle').hover(function() {
             $('#sidePanel').stop(true, false).animate({
             'left': '0px'
             }, 900);
             }, function() {
             jQuery.noConflict();
             });
             
             jQuery('#sidePanel').hover(function() {
             // Do nothing
             }, function() {
             jQuery.noConflict();
             jQuery('#sidePanel').animate({
             left: '-201px'
             }, 800);
             });	
             });
             */
<?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>

        </script>

    </head>
    <body>
                
        <div id="sac">
            <div id="mainNav">
                <?php include "main_nav.php"; ?>
            </div>
            <!--
            <div>
            <?php include "daemon_frame.php"; ?>
            </div>
            <div id="sidePanel">
                    <div id="panelContent">
            <?php include "left_nav.php"; ?>      
                    </div>
                    <div id="panelHandle"><p>></p></div>
                    
            </div>
            -->
            <!--<div style="margin: 0px auto; width: 80%; clear: both;">-->
            <div style="clear: both; overflow: auto;">
                <div id="info"></div>
                <?php
                
                
                if (!isset($_REQUEST['destino']))
                    include $frame1url;
                ?>
            </div>
        </div>
    </body>
</html>
